problem with dbi oracle blob

problem with dbi oracle blob

am 25.05.2011 13:45:13 von Marco van Kammen

--_009_04AAC626111C2B41BCBB54D144C76AA7010B8629MIRAMAIL10mir ab_
Content-Type: multipart/alternative;
boundary="_000_04AAC626111C2B41BCBB54D144C76AA7010B8629MIRAM AIL10mirab_"

--_000_04AAC626111C2B41BCBB54D144C76AA7010B8629MIRAMAIL10mir ab_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi List,

I'm struggeling with the following:

There is a blob field in the oracle db which contains xml...
I want to read this blob and make a single xml file out of it...
Now when using the code below I get the data out of the blob with parts of =
xml but its all messed up...

¬í^@^Esr^@^Porg.jdom.Element°^]<84>=C3^Q=C3^D:^C^@^CL^@
attributest^@^XLorg/jdom/AttributeList;L^@^Gcontentt^@^VLorg /jdom/ContentLi=
st;L^@^Dnamet^@^RLjava/lang/String;xr^@^Porg.jdom.ContentB=C 3=A1<91>=C3bS<9=
9>G^B^@^AL^@^Fparentt^@^QLorg/jdom/Parent;xppsr^@^Vorg.jdom. AttributeList =
^YZ¨té=C3^@^CI^@^Dsize[^@^KelementDatat^@^U[Lorg/j dom/Attri=
bute;L^@^Fparentt^@^RLorg/jdom/Element;xp^@^@^@^@pq^@~^@^Fsr ^@^Torg.jdom.Co=
ntentList^@^@^@^@^@^@^@^²4^B^@^@xp^@^@^@^Hsq^@~^@^@q^@~ ^@^Fsq^@~^@^G^@=
^@^@^@pq^@~^@^Psq^@~^@^K^@^@^@^Guq^@~^@^^@^S[Lorg.jdom.Conte nt;]=C3+m­=
=C3
N^@^@^@^Hsq^@~^@^@q^@~^@^Psq^@~^@^G^@^@^@^@pq^@~^@^Tsq^@~^@^ K^@^@^@^Auq^@~^=
@^N^@^@^@^Esr^@^Morg.jdom.Text^Oö=C3hw"m<89^B^@^AL^@^Evalueq^@~^@^Cxq^=
@~^@^Dq^@~^@^Tt^@^QmkjjKL565udFGJERdppppq^@~^@^Tt^@^Ksecurit yKeyt^@^@t^@3ht=
tp://www.mondial-assistance.com/ecommerce/schema/w^A^@xsq^@~ ^@^@q^@~^@^Psq^=
@~^@^G^@^@^@^@pq^@~^@^^sq^@~^@^K^@^@^@^Auq^@~^@^N^@^@^@^Esq^ @~^@^Xq^@~^@^^t=
^@^CTSVppppq^@~^@^^t^@^KpartnerNameq^@~^@^\q^@~^@

Etc etc.... Code below...

#!/usr/bin/perl
use warnings;
use strict;
use DBI;

my $db =3D DBI->connect("dbi:Oracle:host=3D????;sid=3D???", "???", "???", {=
RaiseError =3D> 1}) or die "$DBI::errstr";

open XML, ">./xmlfile"
or die "Can't create xml file ($!)";

# Set Max BLOB size
$db->{LongReadLen} =3D 150000;

# Select statement
my $SEL =3D "select xml_message from table where bla =3D 'bla'";

# Prepare select
my $sth =3D $db->prepare($SEL);

# Execute select
$sth->execute();
my @row =3D $sth->fetchrow_array();

print XML "$row[0]\n";

# Disconnect from DB when finished
$db->disconnect if defined($db);



Any help is appreciated!

[cid:blank29.gif]
Marco van Kammen
Applicatiebeheerder
[cid:blank4823.gif]


[cid:blank6784.gif]
Mirabeau | Managed Services Dr. C.J.K. van Aalstweg 8F 301, 1625 NV Hoor=
n
+31(0)20-5950550 - www.mirabeau.nl
[Mirabeau]

[cid:leaf3d6c.gif] Please consider the environment before printing thi=
s email




--_000_04AAC626111C2B41BCBB54D144C76AA7010B8629MIRAMAIL10mir ab_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">

1">





Hi List,


 


I’m struggeling with the following:=


 


There is a blob field in the oracle db which contain=
s  xml…


I want to read this blob and make a single xml file =
out of it…


Now when using the code below I get the data out of =
the blob with parts of xml but its all messed up…


 


¬í^@^Esr^@^Porg.jdom.Element°^]<84=
>=C3^Q=C3^D:^C^@^CL^@


attributest^@^XLorg/jdom/AttributeList;L^@^Gcontentt=
^@^VLorg/jdom/ContentList;L^@^Dnamet^@^RLjava/lang/String;xr ^@^Porg.jdom.Co=
ntentBá<91>=C3bS<99>G^B^@^AL^@^Fparentt^@^QLorg/jdom/Paren=
t;xppsr^@^Vorg.jdom.AttributeList       =
^YZ¨té=C3^@^CI^@^Dsize[^@^KelementDatat^@^U[Lorg/j dom/Attribute;=
L^@^Fparentt^@^RLorg/jdom/Element;xp^@^@^@^@pq^@~^@^Fsr^@^To rg.jdom.Content=
List^@^@^@^@^@^@^@^²4^B^@^@xp^@^@^@^Hsq^@~^@^@q^@~^@^Fs q^@~^@^G^@^@^@^=
@pq^@~^@^Psq^@~^@^K^@^@^@^Guq^@~^@^^@^S[Lorg.jdom.Content;]= C3 +m­=
=C3


N^@^@^@^Hsq^@~^@^@q^@~^@^Psq^@~^@^G^@^@^@^@pq^@~^@^T=
sq^@~^@^K^@^@^@^Auq^@~^@^N^@^@^@^Esr^@^Morg.jdom.Text^O=C3=B 6=C3hw "m&l=
t;89^B^@^AL^@^Evalueq^@~^@^Cxq^@~^@^Dq^@~^@^Tt^@^QmkjjKL565u dFGJERdppppq^@~=
^@^Tt^@^KsecurityKeyt^@^@t^@3http://www.mondial-assistance.c om/ecommerce/sc=
hema/w^A^@xsq^@~^@^@q^@~^@^Psq^@~^@^G^@^@^@^@pq^@~^@^^sq^@~^ @^K^@^@^@^Auq^@=
~^@^N^@^@^@^Esq^@~^@^Xq^@~^@^^t^@^CTSVppppq^@~^@^^t^@^Kpartn erNameq^@~^@^\q=
^@~^@


 


Etc etc…. Code below…


 


#!/usr/bin/perl


use warnings;


use strict;


use DBI;


 


my $db =3D DBI->connect("dbi:Oracle:host=3D?=
???;sid=3D???", "???", "???", {RaiseError =3D> =
1}) or die "$DBI::errstr";


 


open XML, ">./xmlfile"


  or die "Can't create xml file ($!)"=
;


 


# Set Max BLOB size


$db->{LongReadLen} =3D 150000;


 


# Select statement


my $SEL =3D "select xml_message from table wher=
e bla =3D 'bla'";


 


# Prepare select


my $sth =3D $db->prepare($SEL);


 


# Execute select


$sth->execute();


my @row =3D $sth->fetchrow_array(); >

 


print XML "$row[0]\n";


 


# Disconnect from DB when finished


$db->disconnect if defined($db);


 


 


 


Any help is appreciated!


 




0" width=3D"100%">






or=3D"#ffffff" align=3D"left">


























3D"" =3D"16">
LOR: #666; FONT-SIZE: 12px">
Marco van Kammen
LOR: #666; FONT-SIZE: 12px">
Applicatiebeheerder
3D"" =3D"8">

lor=3D"#cccccc">





3D"" " width=3D"1" height=3D"1">

3D"" =3D"8">















LOR: #666; FONT-SIZE: 12px">
Mirabeau | Managed Services &=
nbsp;  Dr. C.J.K. van Aalstweg 8F 301, 1625 NV Hoorn

+31(0)20-5950550  -   DECORATION: none" href=3D"http://www.mirabeau.nl">www.mirabeau.nl

3D"Mirabeau" cid:miralogo4ae1.png">









3D"" =3D"16" height=3D"16">
SIZE: 12px">
Please consider the environment before printing thi=
s email









--_000_04AAC626111C2B41BCBB54D144C76AA7010B8629MIRAMAIL10mir ab_--

--_009_04AAC626111C2B41BCBB54D144C76AA7010B8629MIRAMAIL10mir ab_
Content-Type: image/gif; name="blank29.gif"
Content-Description: blank29.gif
Content-Disposition: inline; filename="blank29.gif"; size=43;
creation-date="Wed, 25 May 2011 11:45:15 GMT";
modification-date="Wed, 25 May 2011 11:45:15 GMT"
Content-ID:
Content-Transfer-Encoding: base64

R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==

--_009_04AAC626111C2B41BCBB54D144C76AA7010B8629MIRAMAIL10mir ab_
Content-Type: image/gif; name="blank4823.gif"
Content-Description: blank4823.gif
Content-Disposition: inline; filename="blank4823.gif"; size=43;
creation-date="Wed, 25 May 2011 11:45:15 GMT";
modification-date="Wed, 25 May 2011 11:45:15 GMT"
Content-ID:
Content-Transfer-Encoding: base64

R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==

--_009_04AAC626111C2B41BCBB54D144C76AA7010B8629MIRAMAIL10mir ab_
Content-Type: image/gif; name="blank18be.gif"
Content-Description: blank18be.gif
Content-Disposition: inline; filename="blank18be.gif"; size=43;
creation-date="Wed, 25 May 2011 11:45:15 GMT";
modification-date="Wed, 25 May 2011 11:45:15 GMT"
Content-ID:
Content-Transfer-Encoding: base64

R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==

--_009_04AAC626111C2B41BCBB54D144C76AA7010B8629MIRAMAIL10mir ab_
Content-Type: image/gif; name="blank6784.gif"
Content-Description: blank6784.gif
Content-Disposition: inline; filename="blank6784.gif"; size=43;
creation-date="Wed, 25 May 2011 11:45:15 GMT";
modification-date="Wed, 25 May 2011 11:45:15 GMT"
Content-ID:
Content-Transfer-Encoding: base64

R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==

--_009_04AAC626111C2B41BCBB54D144C76AA7010B8629MIRAMAIL10mir ab_
Content-Type: image/png; name="miralogo4ae1.png"
Content-Description: miralogo4ae1.png
Content-Disposition: inline; filename="miralogo4ae1.png"; size=1445;
creation-date="Wed, 25 May 2011 11:45:15 GMT";
modification-date="Wed, 25 May 2011 11:45:15 GMT"
Content-ID:
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAAKEAAAAYCAIAAAAd9gpcAAAAAXNSR0IArs4c 6QAAAARnQU1BAACx
jwv8YQUAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAF KklEQVRoQ+2aPWsV
URCG70/wJ9jbWFpaWQvpJaUWgmIZEAsLbbQQsVO0UkFSJIUWMaCgREEDKnKb pEgEA4GghBRp9MWB
4c07s2d37+5Kig2L3N2d8zXPfJ2zTv6Mf8dJA8+W7vc+nUnvPY4ddtFAc8Y7 uz++Tj/wtX/wOx16
ZNyFSP9tmzMG3bmLp/jCk5zxl+mNeEXRvV+fo9jO7qpJbmw94rf2cP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KBcwUlUSM9zoJwy4xQwoIpP C+aEcepPbpLdGctq
fcvLYRy/wYMvScluc8zYW+GtELL5C2NLH3KZ9cgOIkrKgZ2X7jIuUga6QvEo SUo2XQ39OHqw4Yy1
mJ1+2F/CGE9lAbwr7c4Y/QvOfznmiNt5Rc1hR9RnWbBJzeXFXZNQYdrndJ5+ DpFo55bKh3RVKbzq
+0rZj+Hi4q9+Whm/M0LSP0PljGWiXDr2wljCNZxA3DT9xCQyVq/VMgbg5vtj O6AtVM5ucyLDblBO
5Lxfjym5EKsRqKWcxr7Ze+AjTLDnVxM+kXddIFzzczmG9FdeFWNVLG8Do7e0 8/gKJgW/ceH0s535
OndoYjI0C8AmpG7HbfwIIU8gg+hatXymIkOzlvA75gtERzOgiNaf1NZcCMJW VEsJ7WdhiOfyIXn8
fyAFhffzCrZe5srD1DKGMBBGkBbnsT+Okx4Z9wOyr16aMG471si4rcaGlR8Z D6vf49A773n6ms9f
BCAcUKoFpmwAAAAASUVORK5CYII=

--_009_04AAC626111C2B41BCBB54D144C76AA7010B8629MIRAMAIL10mir ab_
Content-Type: image/gif; name="leaf3d6c.gif"
Content-Description: leaf3d6c.gif
Content-Disposition: inline; filename="leaf3d6c.gif"; size=665;
creation-date="Wed, 25 May 2011 11:45:15 GMT";
modification-date="Wed, 25 May 2011 11:45:15 GMT"
Content-ID:
Content-Transfer-Encoding: base64

R0lGODlhEAAQAIZ/AKbEVp2sdPf39u7v7LvSerHLbLnRfJ64W8rRtZ/CRYal MvPz7avGYanGWq/K
apWrWP7+/n6dL5u9Qp29TZm6P+7x597e3pO2NrTMcbXNda7JZqzIYqO6Zpm7 O7/Th4KfMqvIYHqX
LaDEQ4ysNeDg4Ofp4LPNc6PDSvP18L7KnqbBX/r89puuadLgq5i8OsTYkY2u MtjktcPWjoOkMcXN
sKTCU4miSaGycvDw8JW0RJy+QY2lTvf68bbQc77ShNvd1sTXko6vNPT185uo eK29grjPec3Tu3eT
Laqvmtva2qmwk77IoarKV63Ccr3Ufu704Ja3O6Wuj4ScRZ2/P4OkL+fn58zW sKSygourM5e4QYmp
NrzSf/z9+rfBnIKhMIeoMr3Qi4SiMbHOZZa5NsXLuaXDVNvnu73Ug5CxN9Tl p5OwRI+yNZa2QZ/A
SKO3aqzKXZ2/RJCrSoylSqfFWaW1eqrHXfj59La/nIKeN7bPd8XZi+fv06LC T9zf0////////yH/
C05FVFNDQVBFMi4wAwEBAAAh+QQBAAB/ACwAAAAAEAAQAAAI4wD9CBxIsOCf ggW5rOBBw8jBgnb2
mInRAkwTFW4eCizRhcWEBhsKGHiRhsPDBXcevCGw5YwHGS886DHpB0WACWI0 aDBhIo8BHwacHDiI
IAeTGmUAzGGQoYgBEz2GCrghAk6bNh3KOMCQwQGIDQ7+VNgxZcwFGFnqbAAB ogEAPkDE2nCx5gOb
BDooSNB7Qs0TsXI6RPgCRUuECF4UXMBjxc+fBQ9GKFYQ4kiID1ikIBB4cAgV EWhmhBkRJE6AEgP/
9LmyJAWRG3SiIPlhUAkZgUIGDICA0HESCyR+kyBRBYcAgwEBADs=

--_009_04AAC626111C2B41BCBB54D144C76AA7010B8629MIRAMAIL10mir ab_--

Re: problem with dbi oracle blob

am 31.05.2011 11:27:11 von Chris Nehren

On Wed, May 25, 2011 at 11:45:13 +0000 , Marco van Kammen wrote:
> Hi List,
>
> I'm struggeling with the following:
>
> There is a blob field in the oracle db which contains xml...
> I want to read this blob and make a single xml file out of it...
> Now when using the code below I get the data out of the blob with parts of xml but its all messed up...
> [nasty encoded data snipped]

Are you certain the column isn't encoded somehow, say with a compression
algorithm or something of that sort? What do Oracle's docs say on the
matter?

> #!/usr/bin/perl
> use warnings;
> use strict;
> use DBI;
>
> my $db = DBI->connect("dbi:Oracle:host=????;sid=???", "???", "???", {RaiseError => 1}) or die "$DBI::errstr";
>
> open XML, ">./xmlfile"
> or die "Can't create xml file ($!)";
>
> # Set Max BLOB size
> $db->{LongReadLen} = 150000;
>
> # Select statement
> my $SEL = "select xml_message from table where bla = 'bla'";
>
> # Prepare select
> my $sth = $db->prepare($SEL);
>
> # Execute select
> $sth->execute();
> my @row = $sth->fetchrow_array();
>
> print XML "$row[0]\n";
>
> # Disconnect from DB when finished
> $db->disconnect if defined($db);

Your DBI code looks reasonable. I would suggest using the three-argument
form of open with a lexical filehandle, though, like so:

open my $xml, '>', './xmlfile' or die ...

This way is safer and more robust, plus $xml is easier to deal with than
the global XML (try passing XML to a function: it's not immediately
obvious how). I can't see this as related to your issue, but it's good
form nonetheless.

--
Chris Nehren | Coder, Sysadmin, Masochist
Shadowcat Systems Ltd. | http://shadowcat.co.uk/

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/